package com.example.sup.singleton;

/**
 * @ClassName StaticSingletonPattern
 * @Description {TODO}
 * @Author 智邦教育.陈超
 * @Date 4:56 下午 2024/7/31
 * @Version 1.0
 */
public class StaticSingletonPattern {
    public static void main(String[] args) {
        System.out.println(Student2.getInstance());//正在做到懒加载，而且可以防止反序列化破坏单例
        System.out.println(Student2.getInstance());//正在做到懒加载，而且可以防止反序列化破坏单例
        System.out.println(Student2.getInstance());//正在做到懒加载，而且可以防止反序列化破坏单例
    }
}
class Student2{
    /*1.构造方法私有*/
    private Student2(){}
    private static class Student2Holder{//静态内部类
        private static Student2 student2 = new Student2();
    }
    public static Student2 getInstance(){
        return Student2Holder.student2;
    }
}